﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Ext.Net;


public partial class CRM_Store_ERP_BusinessQuery : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ViewState_OrderSre = "InDate desc";
            StoreBind();
            gridPanel_listdata.Reload();
        }
    }

    private void StoreBind()
    {
        if (BS_PerStore == 1)
        {
            DataTable dt = CommonLib.BLL.BS_DATASET_SQL.SqlGetTable("select * from VIEW_STORE where STOREROOM_LEVEL='中心库房'");
            Store_Rome.DataSource = dt;
            Store_Rome.DataBind();
            DataTable dtUser = CommonLib.BLL.SYS_USER.GetList("USER_ID='" + BS_LoginUserID + "'").Tables[0];
            Store_USER.DataSource = dtUser;
            Store_USER.DataBind();
        }
        else
        {
            if (BS_LoginRoles.Contains("01") || BS_LoginRoles.Contains("02"))
            {
                BindCenterStore(Store_Rome, Request.QueryString["tabid"]);
                DataTable dtUser = CommonLib.BLL.SYS_USER.GetList("IS_MANAGER=1").Tables[0];
                Store_USER.DataSource = dtUser;
                Store_USER.DataBind();
            }
        }
    }


    string _QueryString;
    private string GetQryString()
    {
        string result = " 1=1 ";
        if (extcomb_STOREROOM_ID.SelectedItem.Text != "" || extcomb_USER.SelectedItem.Text != "")
        {
            if (!string.IsNullOrEmpty(extcomb_STOREROOM_ID.SelectedItem.Text.Trim()))
                result += " and StoreRoomId=" + extcomb_STOREROOM_ID.SelectedItem.Value;
            if (!string.IsNullOrEmpty(extcomb_USER.SelectedItem.Text.Trim()))
                result += " and Owner='" + extcomb_USER.SelectedItem.Value + "'";
            if (!string.IsNullOrEmpty(exttxtf_CargoName.Text.Trim()))
                result += " and CargoName like '%" + exttxtf_CargoName.Text.Trim() + "%'";
            if (extcomb_BUSINESSTYPE.SelectedItem.Text != "全部" && !string.IsNullOrEmpty(extcomb_BUSINESSTYPE.SelectedItem.Text.Trim()))
            {
                if (extcomb_BUSINESSTYPE.SelectedItem.Text == "借出")
                    result += " and BUSINESSTYPE in (1)";
                else
                    result += " and BUSINESSTYPE in (2)";
            }
            else
            {
                result += " and BUSINESSTYPE in (1,2)";
            }
            if (!string.IsNullOrEmpty(exttxtf_CargoCode.Text.Trim()))
                result += " and CargoCode like '%" + exttxtf_CargoCode.Text.Trim() + "%'";
            if (!string.IsNullOrEmpty(exttxtf_LendNo.Text.Trim()))
                result += " and BUSINESSNO like '%" + exttxtf_LendNo.Text.Trim() + "%'";
            if (extdate_start.SelectedValue != null)
                result += " and InDate >'" + extdate_start.Value.ToString() + "'";
            if (extdate_end.SelectedValue != null)
                result += " and InDate <='" + extdate_end.Value.ToString() + "'";
        }
        else
            result += " and 1=2";
        return result;
    }

    protected void MyData_Refresh(object sender, StoreRefreshDataEventArgs e)
    {
        _QueryString = GetQryString();
        int count = 0;
        count = CRMMis.BLL.ERP_BusinessLog.GetRecorderCount(_QueryString);
        BindGridPSData(e, ViewState_OrderSre, PagingToolbar1, Store1, count);
    }

    public override DataTable GetPSData(int PageSize, int CurPage, string OrderStr)
    {
        ViewState_OrderSre = OrderStr;
        DataTable dt = null;
        dt = CRMMis.BLL.ERP_BusinessLog.GetPageList(PageSize, CurPage, _QueryString, ViewState_OrderSre).Tables[0];
        return dt;
    }
}